package cn.yunhe.actions;

import cn.yunhe.model.District;
import cn.yunhe.model.Street;
import cn.yunhe.service.DistrictBiz;
import cn.yunhe.util.BaseActionUtil;
import cn.yunhe.util.ModelDisplayUtil;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/*spring注解*/
@Controller(value = "districtAction")
@Scope(value = "prototype")
/*struts2注解*/
/*@ParentPackage(value = "struts-default")*/
@ParentPackage(value = "json-default")
public class DistrictAction extends BaseActionUtil {

    List<District>districtList=new ArrayList<>();

    /*spring注解*/
    @Autowired
    @Qualifier("districtBiz")
    DistrictBiz districtBiz;

    /*struts2注解*/
    @Action(value = "district_searchDistrict1",results = {
            @Result(name = "success",location = "/searchDistrict.jsp"),
            @Result(name = "error",location = "/fail2SearchDistrict.jsp"),
    })
    public String searchDistrict(){
        //此处的District1对应
        //@Entity(name = "District1")
        //@Table(name = "district")
        List<District>districtList=districtBiz.searchDistrict("from District1");
        getRequest().setAttribute("districtList1",districtList);

        ModelDisplayUtil.listDistrict(districtList);
        return SUCCESS;
    }

    /*struts2注解*/
    @Action(value = "district_searchDistrict",results = {
            @Result(name = "success",location = "/searchDistrict.jsp"),
            @Result(name = "error",location = "/fail2SearchDistrict.jsp"),
            @Result(name = "districtList1",type = "json",params = {"root","districtList"}),
    })
    public String searchDistrict1(){
        //此处的District1对应
        //@Entity(name = "District1")
        //@Table(name = "district")
       districtList= districtBiz.searchDistrict("from District1");
        //getRequest().setAttribute("districtList1",districtList);

        ModelDisplayUtil.listDistrict(districtList);
        //return SUCCESS;
        return "districtList1";
    }

    public DistrictBiz getDistrictBiz() {
        return districtBiz;
    }

    public void setDistrictBiz(DistrictBiz districtBiz) {
        this.districtBiz = districtBiz;
    }

    public List<District> getDistrictList() {
        return districtList;
    }

    public void setDistrictList(List<District> districtList) {
        this.districtList = districtList;
    }
}
